from sqlalchemy import *
from sqlalchemy.orm import sessionmaker
from sqlalchemy.ext.declarative import declarative_base

engine = create_engine('mysql+pymysql://wangjialei:wjl12345@localhost:3306/wangjialei?charset=utf8')
DBSession = sessionmaker(bind=engine)
SQLSession = DBSession()
Base = declarative_base()


class song(Base):
    __tablename__ = 'song'
    song_id = Column(Integer, primary_key=True)
    song_name = Column(String(50))
    song_album = Column(String(50))
    song_interval = Column(String(50))
    song_songmid = Column(String(50))
    song_singer = Column(String(50))


Base.metadata.create_all(engine)


def insert_data(song_dict):
    engine = create_engine('mysql+pymysql://wangjialei:wjl12345@localhost:3306/wangjialei?charset=utf8')
    DBSession = sessionmaker(bind=engine)
    SQLSession = DBSession()
    data = song(song_name=song_dict['song_name'],
                song_album=song_dict['song_album'],
                song_interval=song_dict['song_interval'],
                song_songmid=song_dict['song_songmid'],
                song_singer=song_dict['song_singer'], )
    SQLSession.add(data)
    SQLSession.commit()
